<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="com.iris.egrant.service.ServiceUtils"%>
<%@page import="java.net.URLEncoder"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="${res}/js/message.tips.js"></script>
<script type="text/javascript" src="${res}/js/message.tips-zh_CN.js"></script>
<script type="text/javascript" src="${res}/js/jquery/jquery.js"></script>
<script type="text/javascript" src="${res}/js/jquery/jquery.form.js"></script>
<script type="text/javascript" src="${res}/js/jquery/validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="${res}/js/proposal/irisPrpPrepare.js"></script>
<script type="text/javascript" src="${res}/js/validate/irisvalidator.js"></script>
<script type="text/javascript" src="${res}/js/autodisckey/autodisckey.js"></script>

    <title>录入研究成果</title>
	<script type="text/javascript" language="javascript">
			$.ajaxSetup ({
				cache: false //close AJAX cache
			});
			$(function(){ 
					if('${param.targetURL}' != ''){
						$('#pmainTable').hide();
						$('#pmain').load("${ctx}/proposal/edit/PrpResult/${param.targetURL}?flag=${param.flag}&xmlData="+encodeURIComponent("${param.xmlData}"),function(){InitData();});
					}
			});
			
				function addProduct(val){
					var iVal = parseInt(val);
					var url = "";
					var product_type_name = "";
					switch(iVal){
						case 1: url="PrizeEdit";product_type_name="奖励";break;
						case 2: url="BookEdit";product_type_name="书";break;
						case 3: url="LiteratureEdit";product_type_name="书籍章节";break;
						case 4: url="TreatiseEdit";product_type_name="会议论文";break;
						case 5: url="JournalEdit";product_type_name="期刊文章";break;
						case 6: url="PatentsEdit";product_type_name="专利";break;
						case 7: url="DissertationEdit";product_type_name="学位论文";break;
						case 8: url="OtherEdit";product_type_name="其他";break;
					}
					
					if(url == ""){
						$('#pmain').empty();
						return;
					}
					
					$('#pmain').load("${ctx}/proposal/edit/PrpResult/"+url+"?flag=add&xmlData="+encodeURIComponent("${param.xmlData}")+"&product_type="+val+"&product_type_name="+encodeURIComponent(product_type_name),function(){InitData();});
					$('#pmainTable').hide();
				}
				
				
				
				
				function checkProductAmount(product_type){
					
					var parentwin = parent;
					var parentdoc = parentwin.document;
					var parenttbl = "tblExecuteProducts";
					var parentsel = "selExecuteProducts";
					var grantCode = parentdoc.getElementById("grantCode").value;
					var tbllen = parentdoc.getElementById(parenttbl).rows.length - 2;
					var category_id = 0;
					var allowAmount = 0;
					var count = 0;
					if(product_type == "1"){//奖励
						category_id = 3;
					} else if(product_type == "6"){//专利
						category_id = 2;
					} else {
						category_id = 1; //除去以上2种成果都归为第三类
					}
					
					if(grantCode == "1" || grantCode == "2" || grantCode == "7" || grantCode == "9" || grantCode == "10")
						allowAmount = 20;
					else 
						allowAmount = 10;
						
					var tblObj = parentdoc.getElementById(parenttbl);
					for(var i =0;i<tbllen;i++){
						if(tblObj.rows[i+2].cells[0].childNodes[6].value == category_id){
							count++;
						}
					}
					if(count >= allowAmount){
						alert("此类成果数量不能多于"+allowAmount);
						document.getElementById("product_type").value = "";
						$('#pmain').empty();
						return false;
					}else{
						return true;
					}
				}
				
			</script>
	<style>
	 
 	</style>
	
	
  </head>
  	
  <body>
  				<table id="pmainTable" class="table01 t_css">
  					<tr>
	  					<th><font size='2'>选择成果类型：</font>
	  					<select name="product_type" id="product_type" onchange="if(checkProductAmount(this.value))addProduct(this.value);">
	  						<option></option>
	  						<option value='1'>奖励</option>
	  						<option value='2'>书</option>
	  						<option value='3'>书籍章节</option>
	  						<option value='4'>会议论文</option>
	  						<option value='5'>期刊文章</option>
	  						<option value='6'>专利</option>
	  						<option value='7'>学位论文</option>
	  						<option value='8'>其他</option>
	  					</select>
	  					</td>
  					</tr>
  				</table>
  				<div id="pmain" style="width:auto;height:auto;">
  				</div>
  </body>
</html>
